package org.zoomdev.zoom.aop.modules;

import org.zoomdev.zoom.aop.ProxyFactory;
import org.zoomdev.zoom.aop.annotations.ProxyInterface;
import org.zoomdev.zoom.common.utils.Classes;
import org.zoomdev.zoom.ioc.IocConstructor;
import org.zoomdev.zoom.ioc.IocFactory;
import org.zoomdev.zoom.ioc.IocKey;

final class IocProxyFactory implements IocFactory {
    private final ProxyFactory factory;

    IocProxyFactory(ProxyFactory factory) {
        this.factory = factory;
    }

    @Override
    public IocConstructor createConstructor(IocKey key) {
        if (Classes.isAnnotationPresent(key.getType(), ProxyInterface.class)) {
            ProxyInterface proxy = ((Class<?>) key.getType()).getAnnotation(ProxyInterface.class);
            return new ProxyConstructor(factory, proxy.config());
        }

        return null;
    }
}
